package com.vf.admin.client.service.impl;

import com.vf.admin.client.dao.AgentUserWithdrawDao;
import com.vf.admin.client.service.AgentUserService;
import com.vf.admin.client.service.AgentUserWithdrawService;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AgentUser;
import com.vf.admin.miaodong.entity.AgentUserWithdraw;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AgentUserWithdrawServiceImpl implements AgentUserWithdrawService {

    @Autowired
    AgentUserWithdrawDao agentUserWithdrawDao;
    @Autowired
    AgentUserService agentUserService;

    @Override
    public List<AgentUserWithdraw> page(SplitPageBean splitPage) {
        List<AgentUserWithdraw> page = agentUserWithdrawDao.page(splitPage);
        for(AgentUserWithdraw p : page) {
            AgentUser agentUser = agentUserService.get(p.getAgentUserId());
            p.setUsername(agentUser.getUsername());
        }
        return page;
    }

    @Override
    public void withdraw(AgentUserWithdraw param) {
        agentUserService.subMoney(param.getAgentUserId(), param.getMoney());
        agentUserWithdrawDao.add(param);
    }

    @Override
    public void success(Integer id) {
        AgentUserWithdraw agentUserWithdraw = agentUserWithdrawDao.get(id, AgentUserWithdraw.class);
        if(agentUserWithdraw != null && agentUserWithdraw.getStatus() == 0) {
            agentUserWithdraw.setStatus(1);
        }
        agentUserWithdrawDao.update(agentUserWithdraw);
    }

    @Override
    public void reject(Integer id) {
        AgentUserWithdraw agentUserWithdraw = agentUserWithdrawDao.get(id, AgentUserWithdraw.class);
        if(agentUserWithdraw != null && agentUserWithdraw.getStatus() == 0) {
            agentUserWithdraw.setStatus(2);
        }
        agentUserWithdrawDao.update(agentUserWithdraw);
    }

}
